package me.zhengjie.modules.website.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import me.zhengjie.modules.website.domain.FeedbackTable;
import me.zhengjie.modules.website.service.FeedbackTableService;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.GetMapping;
import me.zhengjie.modules.website.domain.PageResult;

import java.time.LocalDateTime;
import java.util.List;

/**
 *
 *
 * @author system
 * @since 2024-10-23 22:25:03
 */
@RestController
@RequestMapping("/api/feedbackTable")
@Api(tags = " 网页-意见建议")
public class FeedbackTableController {

    @Autowired
    private FeedbackTableService feedbackTableService;

    /**
     * 分页查询
     *
     * @param params 查询参数
     * @param startDate 起始时间
     * @param endDate   结束时间
     * @return 分页结果
     */
    @ApiOperation(value = "分页查询", notes = "分页查询", produces = "application/json")
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功")})
    @PostMapping("/findPage")
    public ResponseEntity<PageResult<FeedbackTable>> findPage(
            @RequestBody FeedbackTable params,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startDate,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endDate,
            Pageable pageable) {

        // 调用服务层方法执行分页查询
        PageResult<FeedbackTable> result = feedbackTableService.findPage(params, startDate, endDate, pageable);
        return ResponseEntity.ok(result);
    }

    /**
     * 列表查询
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "列表查询",notes = "列表查询",produces = "application/json")
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功")})
    @PostMapping("/findList")
    public ResponseEntity<List<FeedbackTable>> findList(@RequestBody FeedbackTable params) {
        List<FeedbackTable> result = feedbackTableService.findList(params);
        return ResponseEntity.ok(result);
    }

    /**
     * 查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "查询", notes = "查询详情")
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功")})
    @GetMapping("findById/{id}")
    public ResponseEntity<FeedbackTable> findById(@PathVariable("id") Long id) {
        FeedbackTable feedbackTable = feedbackTableService.findById(id);
        return ResponseEntity.ok(feedbackTable);
    }

    /**
     * 新增
     *
     * @param feedbackTable
     * @return
     */
    @ApiOperation(value = "展示平台-新增", notes = "展示平台-新增数据")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PostMapping("/website/insert")
    public ResponseEntity<FeedbackTable> insert( @Validated  @RequestBody FeedbackTable feedbackTable) {
        FeedbackTable result = feedbackTableService.insert(feedbackTable);
        return ResponseEntity.ok(result);
    }

    /**
     * 修改
     *
     * @param feedbackTable
     * @return
     */
    @ApiOperation(value = "修改", notes = "修改数据")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PutMapping("/update")
    public ResponseEntity<FeedbackTable> update( @Validated  @RequestBody FeedbackTable feedbackTable) {
        FeedbackTable result = feedbackTableService.update(feedbackTable);
        return ResponseEntity.ok(result);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除", notes = "删除数据")
    @DeleteMapping("delete/{id}")
    public ResponseEntity<Void> delete(@PathVariable("id") Long id) {
        feedbackTableService.delete(id);
        return ResponseEntity.ok(null);
    }

}